package com.chenyue.cm.base.config;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.jdbc.core.JdbcTemplate;

import com.alibaba.druid.pool.DruidDataSource;

import lombok.Getter;
@Configuration
public class BaseConfig {
	
	
	@Getter
    public static String UeditorPrePath;
    
    @Value("${lcmaster.upload.prefix}")
    public void setPath(String db) {
    	UeditorPrePath = db;
    }
	
	
	@Getter
    public static String UeditorPath;
 
    @Value("${lcmaster.upload.kindeditorUploadPath}")
    public void setDatabase(String db) {
    	UeditorPath = db;
    }
	
	@Bean(name="configs")
	public Map<String,Object> configs() {
		Map<String,Object> map = new HashMap<>();
		map.put("brokerUrl", "tcp://127.0.0.1:61616");
		map.put("redis.server", "127.0.0.1:6379");
		map.put("redis.pwd", "longcai@123");
		map.put("zoo.server", "127.0.0.1");
		map.put("coreServiceOrdersHost", "192.168.1.214:9027");
		map.put("coreServiceOrdersLicense", "558ab798cf1a460axx7c3c57f7c77fe0");
		System.err.println("初始化加载配置----start");
		System.err.println("初始化加载配置----"+map);
		System.err.println("初始化加载配置----end");
		return map;
	}

	
	@Bean(name="version")
	public String version() {
		System.err.println("初始化版本号");
		return "0.0.0.1";
	}
	 
	
	@Autowired
    private Environment env;
		
	
	private JdbcTemplate jdbcTemplate;
	
	
	@Bean(name="oaJdbcTemplate")
    public JdbcTemplate dataSource() {
        DruidDataSource dataSource = new DruidDataSource();
        dataSource.setUrl(env.getProperty("spring.datasource.url"));
        dataSource.setUsername(env.getProperty("spring.datasource.username"));//用户名
        dataSource.setPassword(env.getProperty("spring.datasource.password"));//密码
        dataSource.setDriverClassName(env.getProperty("spring.datasource.driver-class-name"));
        dataSource.setInitialSize(2);
        dataSource.setMaxActive(20);
        dataSource.setMinIdle(0);
        dataSource.setMaxWait(60000);
        dataSource.setValidationQuery("SELECT 1");
        dataSource.setTestOnBorrow(false);
        dataSource.setTestWhileIdle(true);
        dataSource.setPoolPreparedStatements(false);
        this.jdbcTemplate = new JdbcTemplate(dataSource);
        System.out.println("初始化jdbc");
        return jdbcTemplate;
        
    }
	
	
	
}
